<%@ Page Trace="true" Language="C#" %>

<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>

<H2>TextWriter</H2>

<script runat=server>

	protected void WriteContentsToResponse( TextReader r )
	{
		string line;

		line = r.ReadLine();

		while ( line != null )
		{
			Response.Write(line);
			Response.Write( "<BR>" );
			line = r.ReadLine();
		}

	}

</script>


<%

TextWriter tw;

tw = new TextWriter();



%>
<H3>Reading a String using TextReader</H3>
<P>The following lines are read from a string using StringReader :<BR><BR>

<%
	string text;

	text = "A\nString\nContaining\nMultiple\nLines";
	WriteContentsToResponse( new StringReader(text) );
%>

<H3>Reading a File using TextReader</H3>
<P>The following lines are reader from a file using File using StreamReader :<BR><BR>

<%
	string fileToRead;
	StreamReader sr;


	fileToRead = Server.MapPath("..\\myfile.txt" );

	sr = File.OpenText( fileToRead );

	WriteContentsToResponse(sr);
	sr.Close();
	

%>
<form runat=server>
	<Wrox:ViewSource SourceFile="default.aspx" runat=server />
</form>
